//
//  MaskView.m
//  CCBShop
//
//  Created by lijianhua on 14-12-17.
//  Copyright (c) 2014年 CCB. All rights reserved.
//

#import "MaskView.h"

@implementation MaskView

- (id)init
{
    //    self = [super initWithFrame:frame];
    self = [super initWithFrame:[[UIScreen mainScreen] bounds]];
    if (self) {
        self.maskView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
        [self addSubview:self.maskView];
        self.maskButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.maskButton.frame = [[UIScreen mainScreen] bounds];
        [self.maskButton addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.maskButton];
    }
    return self;
    
}
- (id)initWithImageViewFrame:(CGRect)frame imageName:(NSString *)name
{
//    self = [super initWithFrame:frame];
    self = [super initWithFrame:[[UIScreen mainScreen] bounds]];
    if (self) {
        // Initialization code
        //蒙版
        self.maskView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
        self.maskView.backgroundColor = [UIColor blackColor];
        self.maskView.alpha = 0.75;
        [self addSubview:self.maskView];

        self.maskImageView = [[UIImageView alloc]initWithFrame:frame];
        self.maskImageView.image = [UIImage imageNamed:name];
        [self addSubview:self.maskImageView];
        
        self.maskButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.maskButton.frame = [[UIScreen mainScreen] bounds];
        self.maskButton.backgroundColor = [UIColor clearColor];
//        self.maskButton.alpha = 0.8;
        [self.maskButton addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.maskButton];
    }
    return self;
}

- (void)show
{
    [[[[UIApplication sharedApplication] delegate] window] addSubview:self];
}


- (void)btnClick:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(hidenClick)]) {
        [ self.delegate hidenClick ];
   
    }

//    for (UIView *view  in self.subviews ) {
//        if ([view isKindOfClass:[BottomPopView class]]) {
//            
//            [UIView animateWithDuration:0.25 animations:^{
//                view.frame = CGRectMake(view.x, view.y, 0, 0);
//            }];
//
//        }
//    }
    [self removeFromSuperview];
}
@end
